﻿@namespace Masa.Tsc.Web.Admin.Rcl.Components
@inherits TscComponentBase

<SDataTable Headers="_headers"
            ServerItemsLength="_total"
            ItemsPerPage="_pageSize"
            Items="_data"
            TItem="TraceResponseDto"
            Loading="@Loading"
            Style="@(PageMode ? "" : "height:calc(100% - 475px);width:100%")"
            Class="overflow-x-hidden"
            Height='@(PageMode ? "calc(100vh - 515px)" : "calc(100%);")' SortBy="_sortBy" SortDesc="_sortDesc" OnOptionsUpdate="OnOptionsUpdate">
    <ItemColContent>
        <div class="hover-pointer" @onclick="e=> OpenAsync(context.Item)">
            @if (context.Header.Value == "Operate")
            {
                <SButton Icon>
                    <SIcon OnClick="@(() => OpenAsync(context.Item))">mdi-view-headline</SIcon>
                </SButton>
            }
            else if (context.Header.Value == "Timestamp")
            {
                @(context.Item.Timestamp.UtcFormatLocal(CurrentTimeZone))
            }
            else if (context.Header.Value == "Service")
            {
                @context.Item.Resource[TraceKeyConst.Resource.ServiceName]
            }
            else if (context.Header.Value == "Endpoint")
            {
                <div style="max-width:400px">
                    <TooltipCopy Value="@GetDisplayName(context.Item)" TooltipContentStyle="max-width:400px" />
                </div>
            }
            else if (context.Header.Value == nameof(TraceResponseDto.Duration))
            {
                @FormatDuration((context.Item.EndTimestamp-context.Item.Timestamp).TotalMilliseconds)
            }
            else
            {
                @context.Value
            }
        </div>
    </ItemColContent>
</SDataTable>

<MCard Rounded=true Class="px-6 py-2" Style="border-top-left-radius: 0 !important; border-top-right-radius: 0 !important;">
    <SPagination Class="mt-2" @bind-Page="_page" @bind-PageSize=_pageSize Total=_total OnChange="HandleOnPaginationUpdate" />
</MCard>
<TscTraceDetail @ref="_tscTraceDetail"/>